var a = getApp();

Page({
    data: {
        urlStr: "",
        language: "",
        page: 1,
        tag: "old",
        receive_log: []
    },
    onLoad: function(e) {
        e.tag && this.setData({
            tag: e.tag
        });
        var t = "", g = "";
        "new" == this.data.tag ? (t = "红包领取记录", g = a.getNetAddresss("plugin.redpack-tool.frontend.receiveLog.getList")) : "old" == this.data.tag ? (t = "红包领取记录", 
        g = a.getNetAddresss("plugin.red-packet.api.logs.receiveLogs")) : (t = "额外奖励记录", 
        g = a.getNetAddresss("plugin.red-packet.api.red-packet-logs.getBonusReceiveLogs")), 
        this.setData({
            urlStr: g
        }), wx.setNavigationBarTitle({
            title: t
        }), this.getData();
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onReachBottom: function() {
        this.data.current_page < this.data.last_page ? (wx.showLoading({
            title: "加载中",
            mask: !0
        }), this.setData({
            page: this.data.page + 1
        }), this.getNext(this.data.selected)) : wx.showToast({
            title: "没有更多",
            icon: "none"
        });
    },
    onShareAppMessage: function() {},
    getData: function() {
        var e = this;
        a._getNetWork({
            url: e.data.urlStr,
            data: {
                page: e.data.page
            },
            success: function(a) {
                var t = a.data;
                "new" == e.data.tag ? e.setData({
                    receive_log: t.data.logs.data,
                    member: t.data.member,
                    amount_sum: t.data.receive_total,
                    current_page: t.data.logs.current_page,
                    last_page: t.data.logs.last_page
                }) : "old" == e.data.tag ? e.setData({
                    receive_log: t.data.receive_log.list.data,
                    member: t.data.member,
                    amount_sum: t.data.receive_log.amount_sum,
                    current_page: t.data.receive_log.list.current_page,
                    last_page: t.data.receive_log.list.last_page
                }) : e.setData({
                    receive_log: t.data.receive_log.data,
                    member: t.data.member,
                    amount_sum: t.data.bonus_sum,
                    current_page: t.data.receive_log.current_page,
                    last_page: t.data.receive_log.last_page
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getNext: function() {
        var e = this;
        a._getNetWork({
            url: e.data.urlStr,
            data: {
                page: e.data.page
            },
            success: function(a) {
                var t = a.data;
                if ("new" == e.data.tag) {
                    if (t.data.logs.current_page > t.data.logs.last_page) return wx.hideLoading(), wx.showToast({
                        title: "没有更多",
                        icon: "none"
                    }), void e.setData({
                        current_page: t.data.logs.current_page,
                        last_page: t.data.logs.last_page
                    });
                    wx.hideLoading(), console.log(e.data.receive_log);
                    var g = e.data.receive_log.concat(t.data.logs.data);
                    e.setData({
                        receive_log: g,
                        current_page: t.data.logs.current_page,
                        last_page: t.data.logs.datalast_page
                    });
                } else if ("old" == e.data.tag) {
                    if (t.data.receive_log.list.current_page > t.data.receive_log.list.last_page) return wx.hideLoading(), 
                    wx.showToast({
                        title: "没有更多",
                        icon: "none"
                    }), void e.setData({
                        current_page: t.data.receive_log.list.current_page,
                        last_page: t.data.receive_log.list.last_page
                    });
                    wx.hideLoading(), e.setData({
                        receive_log: e.data.receive_log.concat(t.data.receive_log.list.data),
                        member: t.data.member,
                        amount_sum: t.data.receive_log.amount_sum,
                        current_page: t.data.receive_log.list.current_page,
                        last_page: t.data.receive_log.list.datalast_page
                    });
                } else {
                    if (t.data.receive_log.current_page > t.data.receive_log.last_page) return wx.hideLoading(), 
                    wx.showToast({
                        title: "没有更多",
                        icon: "none"
                    }), void e.setData({
                        current_page: t.data.receive_log.current_page,
                        last_page: t.data.receive_log.last_page
                    });
                    wx.hideLoading(), e.setData({
                        receive_log: e.data.receive_log.concat(t.data.receive_log.data),
                        member: t.data.member,
                        amount_sum: t.data.bonus_sum,
                        current_page: t.data.receive_log.current_page,
                        last_page: t.data.receive_log.last_page
                    });
                }
            },
            fail: function(a) {
                console.log(a);
            }
        });
    }
});